Release 10.1A: OpenEdge Development:
Web Services


Example 4GL accessing a SOAP fault

The following procedure fragment runs an operation on a fictitious Web service that returns a SOAP fault identical to the one described in the beginning of this section (see the "Handling SOAP faults" section). It accesses and begins to examine the SOAP fault message as described in the following steps that match the numbered comments (/*1*/ to /*7*/) in the code.

This code:

  1. Uses the 4GL VALID-HANDLE function to determine if a given ERROR condition (ERROR-STATUS:ERROR = TRUE) is caused by a SOAP fault by testing the validity of the handle returned by the ERROR-STATUS:ERROR-OBJECT-DETAIL attribute.
  2. Assigns a handle variable (hSoapFault) to any valid SOAP fault object returned by the ERROR-STATUS:ERROR-OBJECT-DETAIL attribute for code readability.
  3. Note: You can also use the ERROR-STATUS:ERROR-OBJECT-DETAIL handle attribute directly to work with the SOAP fault object.

  4. Examines the values of SOAP fault elements, as required, using appropriate attributes (SOAP-FAULT-CODE) on the SOAP fault object handle.
  5. Uses the 4GL VALID-HANDLE function to determine if this SOAP fault has SOAP fault detail by testing the validity of the handle returned by hSoapFault:SOAP-FAULT-DETAIL.
  6. Assigns a handle variable (hSoapFaultDetail) to the SOAP fault-detail object returned by the hSoapFault:SOAP-FAULT-DETAIL attribute for code readability.
  7. Note: You can also use the ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-DETAIL handle attribute directly to work with the SOAP fault-detail object.

  8. Returns the root node of the underlying SOAP fault <detail> element by using the hSoapFaultDetail:GET-NODE( ) method to assign the root node to the x-noderef object referenced by the handle variable hxnoderef.
  9. Can now use the methods and attributes of the x-noderef object handle (hxnoderef) and additional handle variables to walk the XML DOM subtree referenced by hxnoderef to examine the content of the SOAP fault <detail> element as specified by the WSDL for the Web service.
  10. Sample SOAP fault procedure
    DEFINE VARIABLE hWS AS HANDLE. 
    DEFINE VARIABLE hStockPortType AS HANDLE. 
    DEFINE VARIABLE price AS DECIMAL. 
    CREATE SERVER hWS. 
    /* Create a WebServicePortType object, using server & port information. */ 
    hWS:CONNECT( "-WSDL http: //www.stockvend.com/application/wsdl/stock.wsdl 
                  -Service stockSVC 
                  -Port stockPort" ). 
    RUN stock SET hStockPortType ON SERVER hWS. 
    RUN getPrice IN hStockPortType( INPUT "error", OUTPUT price ) NO-ERROR. 
    IF ERROR-STATUS:ERROR THEN DO: 
    /*1*/ 
      /* Error occurred on the RUN. Did the Web service generate  
         the error or was it an internal Progress 4GL error? */ 
      IF VALID-HANDLE( ERROR-STATUS:ERROR-OBJECT-DETAIL ) THEN DO: 
        DEFINE VARIABLE hSoapFault as HANDLE. 
    /*2*/ 
        hSoapFault = ERROR-STATUS:ERROR-OBJECT-DETAIL. 
    /*3*/  
        IF INDEX( "VersionMismatch", hSoapFault:SOAP-FAULT-CODE ) THEN DO: 
    /*4*/ IF VALID-HANDLE( hSoapFault:SOAP-FAULT-DETAIL ) THEN DO: 
            DEFINE VARIABLE hSoapFaultDetail as HANDLE. 
    /*5*/   hSoapFaultDetail = hSoapFault:SOAP-FAULT-DETAIL. 
            DEFINE VARIABLE hxnoderef AS HANDLE. 
            CREATE X-NODEREF hxnoderef. 
    /*6*/   hSoapFaultDetail:GET-NODE( hxnoderef ). 
             
    /*7*/   /* From here the application can walk the detail XML and 
               retrieve the relevant information. */ 
            . 
            . 
            . 
          END. /* Examine SOAP-FAULT-DETAIL */ 
        END. /* Return SOAP-FAULT-CODE info */ 
      END. /* Examine ERROR-OBJECT-DETAIL */ 
    END. 
    DELETE PROCEDURE hStockPortType. 
    hWS:DISCONNECT( ). 
    


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095